<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Api\BasicController;
use App\Models\Divination\Divination;
use App\Models\Mental\Lists;
use App\Models\Order\RechargeOrder;
use App\Models\StoreOrderPayment;
use App\Models\StoreShop;
use App\Models\User;
use App\Models\UserCoin;
use App\Models\UserInfo;
use App\Models\Users\MoneyLog;
use App\Models\Users\WithdrawalLog;
use App\Repositories\ResponseCode;
use App\Repositories\ResponseMsg;
use App\Services\Alipay;
use App\Services\Data;
use App\Services\Wechat;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Jiannei\Response\Laravel\Support\Facades\Response;

class PaymentController extends BasicController
{



    /**
     * @api {get} /payment/pay  提交支付
     * @apiName StorePaymentPay
     * @apiGroup StorePayment
     * @apiDescription 提交支付
     *
     * @apiHeader {String} Authorization='Bearer '
     *
     * @apiParam {String} main_no  订单编号
     * @apiParam {Number} pay_type  支付类型1=支付宝2=微信3=余额
     * @apiParam {Number} order_type  订单类型1预约2咨询3测试4占卜问答5充值
     * @apiParam {Number} [trade_pass]  交易密码
     */
    public function pay()
    {
        $order_id = $this->request->input('order_id');
        $pay_type = $this->request->input('pay_type',3);
        $order_type = $this->request->input('order_type');
        try {
            DB::beginTransaction();
            if ($order_type == 3) (new Lists())->pay($this->uid(), $order_id);
            if ($order_type == 4) (new Divination())->pay($this->uid(), $order_id);
            if ($order_type == 5) (new RechargeOrder())->pay($order_id,$pay_type);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            return Response::fail($e->getMessage());
        }
        return Response::ok('支付成功');
    }

    public function recharge(){
        $order_id = $this->request->input('order_id');
        $pay_type = $this->request->input('pay_type');
        if($pay_type=='alipay'){
//            (new Alipay())->app($main_no, $payment->total_pay, config('app.name'));
        }
    }

    public function withdraw(){
        $amount=$this->request->input('amount');
        $account=$this->request->input('account');
        $platform=$this->request->input('platform'); //1支付宝2微信
        try {
            $result= (new WithdrawalLog())->withdrawal($this->uid(),$amount,$account,$platform);
        }catch (\Exception $e){
            return Response::fail($e->getMessage());
        }
        return Response::success($result);

    }
}
